package com.meichis.yndms.vm;


import androidx.lifecycle.MutableLiveData;

import com.meichis.mcsappframework.utils.DateUtil;
import com.meichis.yndms.model.DataTable;
import com.meichis.yndms.model.Notice;
import com.meichis.yndms.repository.manager.NoticeListManager;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * @author xmy
 * @title
 * @remake
 * @create 2021-05-08 16:22
 */
public class NoticeListVM extends MyViewModel {

    private MutableLiveData<List<Notice>> noticeList;
    private MutableLiveData<List<Notice>> unReadNoticeList;
    private MutableLiveData<List<Notice>> readNoticeList;
    private MutableLiveData<Boolean> isRefresh;
    public boolean isReadPage = false;

    private List<DataTable> noticeTypeList;
    private MutableLiveData<DataTable> noticeType;

    private MutableLiveData<String> BeginTime;
    private MutableLiveData<String> EndTime;

    public List<DataTable> getNoticeTypeList() {
        if (noticeTypeList == null) {
            noticeTypeList = new ArrayList<>();
            noticeTypeList.add(new DataTable("", "全部"));
            noticeTypeList.add(new DataTable("系统公告", "系统公告"));
            noticeTypeList.add(new DataTable("产品公告", "产品公告"));
            noticeTypeList.add(new DataTable("新闻", "新闻"));
            noticeTypeList.add(new DataTable("任务公告", "任务公告"));
            noticeTypeList.add(new DataTable("活动通知", "活动通知"));
            noticeTypeList.add(new DataTable("知识类公告", "知识类公告"));
            noticeTypeList.add(new DataTable("新品速递", "新品速递"));
        }
        return noticeTypeList;
    }

    public MutableLiveData<DataTable> getNoticeType() {
        if (noticeType == null) {
            noticeType = new MutableLiveData<>();
            noticeType.setValue(getNoticeTypeList().get(0));
        }
        return noticeType;
    }

    public MutableLiveData<String> getBeginTime() {
        if (BeginTime == null) {
            BeginTime = new MutableLiveData<>();
            BeginTime.setValue(DateUtil.getMultipleMonth(Calendar.getInstance().getTime(), -1, DateUtil.FORMAT_YMD));
        }

        return BeginTime;
    }

    public MutableLiveData<String> getEndTime() {
        if (EndTime == null) {
            EndTime = new MutableLiveData<>();
            EndTime.setValue(DateUtil.getCurDateStr(DateUtil.FORMAT_YMD));
        }
        return EndTime;
    }

    public MutableLiveData<Boolean> getIsRefresh() {
        if (isRefresh == null) {
            isRefresh = new MutableLiveData<>();
            isRefresh.setValue(false);
        }
        return isRefresh;
    }

    public MutableLiveData<List<Notice>> getUnReadNoticeList() {
        if (unReadNoticeList == null) {
            unReadNoticeList = new MutableLiveData<>();
            unReadNoticeList.setValue(new ArrayList<>());
        }
        return unReadNoticeList;
    }

    public MutableLiveData<List<Notice>> getReadNoticeList() {
        if (readNoticeList == null) {
            readNoticeList = new MutableLiveData<>();
            readNoticeList.setValue(new ArrayList<>());
        }
        return readNoticeList;
    }

    public MutableLiveData<List<Notice>> getNoticeList() {
        if (noticeList == null) {
            noticeList = new MutableLiveData<>();
        }
        return noticeList;
    }

    public void GetNotice() {
        NoticeListManager.getInstance().GetNotice(
                getShowDialog(), getUserInfo().getValue().getOrgId(),
                getUserInfo().getValue().getId(), getBeginTime().getValue(), getEndTime().getValue()
                , getNoticeType().getValue().getId(), getNoticeList());
    }

    public void UpdateNoticeRead(String infoId) {
        NoticeListManager.getInstance().UpdateNoticeRead(
                getShowDialog(), getUserInfo().getValue().getOrgId(),
                getUserInfo().getValue().getId(), infoId, new MutableLiveData<>());
    }


}
